%{
#include <stdio.h>
#include <string.h>
#include "fraction.h"

fraction_t *frac;
%}

%union
{
  int number;
  char *string;
}

%token <string> MARK
%token <string> DIV
%token <number> NUMBER
%type <number> simple_number

%%

equation: simple_number
         | simple_number equation
         ;

simple_number: NUMBER 
               {
               	frac = MakeFraction($1, 0, 0);
               	PrintFraction(frac);
               	DeleteFraction(frac);
               }
               | NUMBER DIV NUMBER 
               {
               	frac = MakeFraction(0, $1, $3);
               	PrintFraction(frac);
               	DeleteFraction(frac);
               }
               | NUMBER MARK NUMBER DIV NUMBER 
               {
               	frac = MakeFraction($1, $3, $5);
               	PrintFraction(frac);
               	DeleteFraction(frac);
               }
               ; 

%%

int yyerror(const char *str)
{
  fprintf(stderr,"error: %s\n",str);
}

int yywrap()
{
  return 1;
}



